#include<bits/stdc++.h>
using namespace std;
int t, n, a[20], c[20], mx;
int main () {
    freopen("color.in", "r", stdin);
    freopen("color.out", "w", stdout);
    scanf("%d", &t);
    while(t--) {
        mx = 0;
        scanf("%d", &n);
        for(int i = 0;i < n;++i) scanf("%d", a+i);
        for(int i = 0;i < (1<<n);++i) {
            int ans = 0;
            for(int j = 0;j < n;++j) c[j] = (i>>j)&1;
            for(int j = 0;j < n;++j)
                for(int k = j-1;k >= 0;--k)
                    if(c[j]==c[k]) {ans += (a[j]==a[k])*a[j]; break;}
            mx = max(mx, ans);
        }
        printf("%d\n", mx);
    }
    return 0;
}
